<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *项目管理
*/
defined('BY_JYA') or exit('error');
$merchid=$this->checklogin();
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list0';
$manage_op=array('confirm','cancel','agree','disagree');
if(in_array($_RQ['op'],$manage_op)){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择项目！','error');
	}
}
$tabs=array(
	array('op'=>'edit','title'=>'添加项目','action'=>'manage.good_list'),
	
);
$return['status']=array('0'=>'下架','1'=>'上架','2'=>'爆满','3'=>'回收站');
//售罄项目
if($_RQ['op']=='list0'){
	$params=array('merchid'=>$merchid,'onepluginname'=>'jy_merch','type'=>4);
	$params['uniacid']=$_SESSION['uniacid'];
	$params['status']='3';
	if(!empty($_RQ['name'])){
		$params['name like']='%'.trim($_RQ['name']).'%';
		$return['params']['name']=$_RQ['name'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('id','uniacid','paixu','title','image','pcate','ccate','price','status','createtime');
	$list=pdo_getslice('jy_weishop_goods',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){

		}
	}
	
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'del_one'=>true,'delall'=>true,'list'=>array(
			array('name'=>'paixu','title'=>'排序','type'=>'string'),
			array('name'=>'title','title'=>'项目名称','type'=>'string'),
			array('name'=>'image','title'=>'项目图片','type'=>'image'),
			array('name'=>'pcate','title'=>'一级分类','type'=>'string'),
			array('name'=>'ccate','title'=>'二级分类','type'=>'string'),
			array('name'=>'price','title'=>'价格','type'=>'string'),
			array('name'=>'pay','title'=>'库存','type'=>'string'),
			array('name'=>'coupon','title'=>'服务次数','type'=>'string'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
			array('name'=>'coupon','title'=>'属性','type'=>'string'),
			array('title'=>'恢复','type'=>'post','op'=>'huifu'),
		)),
		'search_one'=>array('name'=>'title','title'=>'项目名称','add'=>false),
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='huifu'){
	$id=$_RQ['id'];
		if($id){
			pdo_update('jy_weishop_goods',array('status'=>1),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
		exi('恢复成功！');
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_weishop_goods',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
			pdo_delete('jy_weishop_goods_spec',array('uniacid'=>$_SESSION['uniacid'],'goodsid'=>$id));
			pdo_delete('jy_weishop_goods_spec_item',array('uniacid'=>$_SESSION['uniacid'],'goodsid'=>$id));
			pdo_delete('jy_weishop_goods_option',array('uniacid'=>$_SESSION['uniacid'],'goodsid'=>$id));
			pdo_delete('jy_weishop_goods_dispatch',array('uniacid'=>$_SESSION['uniacid'],'goodsid'=>$id));
		}
	}
	exi('删除成功！');
}